package com.koch.blockchain;

import com.koch.blockchain.block.Block;
import com.koch.blockchain.block.BlockChain;

import java.text.SimpleDateFormat;
import java.util.Date;

public class App
{
    public static void main( String[] args )
    {
        BlockChain blockchain = BlockChain.newBlockchain();


        System.out.println("创世链的信息：");
        System.out.println("区块的长度："+blockchain.getBlockList().size());

        //4.添加区块
        blockchain.addBlock("tx 1");
        blockchain.addBlock("tx 2");
        blockchain.addBlock("tx 3");

        for(int i=0;i<blockchain.getBlockList().size();i++) {
            Block block = blockchain.getBlockList().get(i);
            System.out.println("第"+block.getHeight()+"个区块信息：");
            System.out.println("\tprevBlockHash: " + block.getPrevBlockHash());
            System.out.println("\tData: " + block.getData());
            System.out.println("\tHash: " + block.getHash());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String date2 = sdf.format(new Date(block.getTimeStamp()*1000L));
            System.out.println("\ttimeStamp:" + date2);
            System.out.println();
        }
    }
}
